package com.woniuxy.store.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.store.app.util.StoreIdUtil;
import com.woniuxy.store.client.param.ApplyParam;
import com.woniuxy.store.client.StoreManageClient;
import com.woniuxy.store.client.param.ModifyApplyParam;
import com.woniuxy.store.client.param.AddContractParam;
import com.woniuxy.store.client.result.ApplyDto;
import com.woniuxy.store.infra.model.StoreApplay;
import com.woniuxy.store.infra.model.StoreContract;
import com.woniuxy.store.service.StoreApplayService;
import com.woniuxy.store.service.StoreContractService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/store/manage")

public class StoreManageClientImpl implements StoreManageClient {

    @Resource
    private StoreApplayService storeApplayService;

    @Resource
    private StoreContractService storeContractService;


    @Override
    @Log("商家申请开店")
    public Result apply(@Valid ApplyParam param) {
        StoreApplay storeApplay = BeanUtil.toBean(param, StoreApplay.class);
        storeApplayService.apply(storeApplay);
        return Result.success();
    }

    @Override
    @Log("处理商家申请")
    public Result<ApplyDto> handApply(Integer applayId ,String storeProcessState) throws IOException {
        StoreApplay storeApplay = storeApplayService.handApply(applayId,storeProcessState);
        ApplyDto applyDto = BeanUtil.toBean(storeApplay, ApplyDto.class);
        return Result.success(applyDto);
    }

    @Override
    @Log("商家修改开店申请")
    public Result<ApplyDto> modifyApply(@Valid ModifyApplyParam param) {
        StoreApplay storeApplay = BeanUtil.toBean(param, StoreApplay.class);
        storeApplayService.modifyApply(storeApplay);
        return Result.success();
    }

    @Override
    @Log("商家签约续费")
    public Result addContract(@Valid AddContractParam param) {
        StoreContract storeContract = storeContractService.addContract(StoreIdUtil.getFromToken(),param.getPackageFunctionId(),param.getBankCardNumber());
        return Result.success(storeContract);
    }
}
